package com.controller;

import com.pojo.TbCompany;
import com.pojo.TbWorker;
import com.service.CompanyService;
import com.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/company")
public class CompanyController {
    @Autowired
    JSONResult jsonResult;
    @Autowired
    CompanyService companyService;

    @GetMapping("/findAllCompanyByCompanyName")
    public JSONResult findAllCompanyByCompanyName(@RequestParam("page")int page,@RequestParam("limit")int limit,@RequestParam(value = "companyName",defaultValue = "-1")String companyName){
        return companyService.findAllCompanyByCompanyName(page,limit,companyName);
    }
    @GetMapping("/findAllCompany")
    public JSONResult findAllCompany(@RequestParam("page")int page,@RequestParam("limit")int limit){
        return companyService.findAllCompany(page,limit);
    }

    @GetMapping("/findAllCompanyByState")
    public JSONResult findAllCompanyByState(@RequestParam("page")int page,@RequestParam("limit")int limit,@RequestParam(value = "state",defaultValue = "-1")int state){
        return companyService.findAllCompanyByState(page,limit,state);
    }


    @PostMapping("/addCompany")
    public JSONResult addCompany(@RequestBody TbCompany tbCompany){
        return companyService.addCompany(tbCompany);
    }


    @GetMapping("/deleteCompany")
    public JSONResult deleteCompany(@RequestParam("companyId")int companyId){
        return companyService.deleteCompany(companyId);
    }


    @PostMapping("/updateCompany")
    public JSONResult updateCompany(@RequestBody TbCompany company){
        return companyService.updateCompany(company);
    }


    @GetMapping("/findCompanyById")
    public JSONResult findCompanyById(@RequestParam("companyId")int companyId){
        return companyService.findCompanyById(companyId);
    }
}
